package com.dw.etl.core.service;

import com.dw.etl.common.util.SnowflakeIdWorker;
import com.dw.etl.common.util.UUIDUtil;
import com.dw.etl.common.vo.PaginationVO;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.EtlBaseService;
import com.dw.etl.core.mapper.EtlBaseMapper;
import com.dw.etl.core.bean.model.EtlBase;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * etlBase服务实现类
 * Created by hozeData on 2021/05/21.
 */
@Service
@Transactional
public class EtlBaseServiceImpl implements EtlBaseService{

    private static final Logger LOGGER = LoggerFactory.getLogger(EtlBaseServiceImpl.class);

    @Autowired
    private EtlBaseMapper etlBaseMapper;

    @Override
    public int insert(EtlBase etlBase) {
        if(etlBase.getIdBase()==null){
            String uuid32 = UUIDUtil.getUUID32();
            etlBase.setIdBase(uuid32);
        }
        return etlBaseMapper.insert(etlBase);
    }

    @Override
    public int insertSelective(EtlBase etlBase)  {
        if(StringUtils.isEmpty(etlBase.getIdBase())){
            String  uuid32 = UUIDUtil.getUUID32();
            etlBase.setIdBase(uuid32);
        }
        return etlBaseMapper.insertSelective(etlBase);
    }

    @Override
    public int deleteById(String idBase)  {
        return etlBaseMapper.deleteByPrimaryKey(idBase);
    }

    @Override
    public int updateByIdSelective(EtlBase etlBase)  {

        return etlBaseMapper.updateByPrimaryKeySelective(etlBase);
    }

    @Override
    public int updateById(EtlBase etlBase)  {
        return etlBaseMapper.updateByPrimaryKey(etlBase);
    }

    @Override
    public EtlBase getById(String idBase)  {
        return etlBaseMapper.selectByPrimaryKey(idBase);
    }

    @Override
    public List<EtlBase> findByModel(EtlBase etlBase)  {
        return etlBaseMapper.findByModel(etlBase);
    }

    @Override
    public PaginationVO<EtlBase> findPageByModel(EtlBase etlBase, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<EtlBase> quesList = etlBaseMapper.findByModel(etlBase);
        PageInfo<EtlBase> pageInfo = new PageInfo<>(quesList);
        PaginationVO<EtlBase> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public PaginationVO<EtlBase> findPageByModelLike(EtlBase etlBase, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<EtlBase> quesList = etlBaseMapper.findByLike(etlBase);
        PageInfo<EtlBase> pageInfo = new PageInfo<>(quesList);
        PaginationVO<EtlBase> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public List<EtlBase> findAllByModel(EtlBase etlBase) {
        return etlBaseMapper.findAllByModel(etlBase);
    }
}
